﻿@model Orchard.Autoroute.Settings.AutorouteSettings

@{
    Script.Require("AutorouteBrowser");
    Style.Require("AutorouteSettings");

    int patternCount = 0;
    int patternCultureCount = 0;

    List<string> cultures = new List<string>();
    cultures.Add(null);
    cultures.AddRange(Model.SiteCultures);
}
<fieldset>
    <div>
        @Html.CheckBoxFor(m => m.AllowCustomPattern)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowCustomPattern)">@T("Allow custom patterns")</label>
        <span class="hint">@T("Allow the user to change the pattern on each item.")</span>
    </div>
</fieldset>
<fieldset>
    <div>
        @Html.CheckBoxFor(m => m.AllowSetAsHomePage)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AllowSetAsHomePage)">@T("Allow \"Set as home page\"")</label>
        <span class="hint">@T("Allow the user to set a content item of this type as the home page.")</span>
        <span class="hint">@T("NOTE: Certain combinations of content type definitions and permission settings can create circumstances for non-Admin users with Dashboard access to remove the home page without the ability to set another one. Use this option with caution.")</span>
    </div>
</fieldset>
<fieldset>
    <div>
        @Html.CheckBoxFor(m => m.AutomaticAdjustmentOnEdit)
        <label class="forcheckbox" for="@Html.FieldIdFor(m => m.AutomaticAdjustmentOnEdit)">@T("Automatically regenerate when editing content")</label>
        <span class="hint">@T("This option will cause the Url to automatically be regenerated when you edit existing content and publish it again, otherwise it will always keep the old route, or you have to perform bulk update in the Autoroute admin.")</span>
    </div>
</fieldset>
@if (Model.SiteCultures.Count > 1) {
    <fieldset>
        <div>
            @Html.CheckBoxFor(m => m.UseCulturePattern, new { @class = "use-culture-pattern" })
            <label class="forcheckbox" for="@Html.FieldIdFor(m => m.UseCulturePattern)">@T("Use culture pattern(s)")</label>
            <span class="hint">@T("Allow to set pattern(s) for each culture. If left unchecked this means it will use the default website culture pattern(s).")</span>
        </div>
    </fieldset>
}
<fieldset>
    <h4>@T("Patterns") :</h4>
</fieldset>
<fieldset>
    <div id="local-navigation">
        <ul class="autoroute-cultures localmenu group">
            @{
                int i = 1;
                string cssClass = "";
            }
            <li class="first selected"><a class="culture" href="#cat-culture-neutral">@T("All cultures")</a></li>
            @foreach (var culture in cultures) {
                if (!String.IsNullOrEmpty(culture)) {
                    cssClass = i == cultures.Count - 1 ? "last" : "middle";
                    <li class="@cssClass" style="@(Model.UseCulturePattern == false ? "display:none;" : "")"><a class="culture" href="#cat-@culture">@culture</a></li>
                    i++;
                }
            }
        </ul>
    </div>
    <div id="content">
        @foreach (var culture in cultures) {
            <fieldset id="cat-@(String.IsNullOrEmpty(culture) ? "culture-neutral" : culture)" class="items @(String.IsNullOrEmpty(culture) ? "default" : "")" style="@(String.IsNullOrEmpty(culture) ? "display:block;" : "display:none;")">
                <table class="autoroute-settings-patterns">
                    <tr>
                        <th class="autoroute-settings-default">@T("Default")</th>
                        <th class="autoroute-settings-name">@T("Name")<span class="hint">@T("Name of the pattern")</span></th>
                        <th class="autoroute-settings-pat">@T("Pattern")<span class="hint">@T("The definition of the pattern")</span></th>
                        <th class="autoroute-settings-desc">@T("Description")<span class="hint">@T("The description of the pattern, displayed in the editor")</span></th>
                        <th class="autoroute-settings-actions">&nbsp;</th>
                    </tr>
                    @for (int index = 0; index < Model.Patterns.Where(x => x.Culture == culture).Count(); index++) {
                        <tr>
                            <td>@Html.RadioButtonFor(m => m.DefaultPatterns[cultures.IndexOf(culture)].Culture, culture + "|" + patternCultureCount, patternCultureCount.ToString() == Model.DefaultPatterns[cultures.IndexOf(culture)].PatternIndex ? new { @checked = "checked" } : null)</td>
                            <td>@Html.TextBoxFor(m => m.Patterns[patternCount].Name, new { @class = "text" })</td>
                            <td>@Html.TextBoxFor(m => m.Patterns[patternCount].Pattern, new { @class = "tokenized text" })</td>
                            <td>@Html.TextBoxFor(m => m.Patterns[patternCount].Description, new { @class = "text" })</td>
                            <td>@Html.HiddenFor(m => m.Patterns[patternCount].Culture)&nbsp;</td>
                        </tr>
                        if (Model.Patterns[patternCount].Pattern != null) { patternCultureCount++; } else { patternCultureCount = 0; }
                        patternCount++;
                    }
                    <tr></tr>
                </table>
            </fieldset>
        }
    </div>
</fieldset>

@Display.TokenHint()
